(() => {
  let vm = new Vue({
    el: "#app",
    data: {
      goodslist: [
        {
          id: 1,
          title: "尼玛杂货店",
          ischeck: false,
          goods: [
            {
              gid: 1,
              title: "这是可以让你变帅的洗面奶",
              ischecked: false,
              img: "./images/1.png",
              size: "支装",
              weight: "250ml",
              num: 1
            },
            {
              gid: 2,
              title: "这是可以让你变帅的剃须刀",
              ischecked: false,
              img: "./images/4.png",
              size: "个",
              weight: "1kg",
              num: 1
            },

          ],
        },
        {
          id: 2,
          title: "好兄弟日用品店",
          ischeck: false,
          goods: [
            {
              gid: 1,
              title: "ck懂都懂得",
              ischecked: false,
              img: "./images/2.png",
              size: "瓶装",
              weight: "600ml",
              num: 1
            },
            {
              gid: 2,
              title: "麦片",
              ischecked: false,
              img: "./images/3.png",
              size: "袋装",
              weight: "750g",
              num: 1
            },
          ],
        },
      ]
    },
    computed: {
      allcheck: {
        get() {
          // console.log(1111);
          let arr = [];
          this.goodslist.forEach((shop) => {
            let res = shop.goods.every((good) => good.ischecked == true);
            arr.push(res)
          })
          return arr.every((item) => item == true)
        },
        set(val) {
          console.log(val);
          this.goodslist.forEach((shop) => {
            shop.goods.forEach((good) => {
              good.ischecked = val;
            });
          });
        }
      }
    },
    methods: {
      change(index) {
        console.log(index);
        console.log(this.goodslist[index]);
        this.goodslist[index].goods.forEach((good) => {
          good.ischecked = !this.goodslist[index].ischeck
        })
      },
      add(inx) {
        console.log(inx);
        console.log("点击增加");
          this.goodslist.forEach((shop) => {
          shop.goods.forEach((good) => {
            let num = good[inx].num;
            num = num + 1;
            good[inx].num = num;
          })
        })
      },
      cut(index,inx) {
        console.log(index,"第几个shop");
        console.log(inx,"第几个商品");
        console.log("点击减少");
        this.goodslist.filter((shop) => shop.index==index
        
        )
        
      }
    },
    watch: {
      goodslist: {
        deep: true,
        handler(goodslist) {
          goodslist.forEach((shop) => {
            shop.ischeck = shop.goods.every((good) => good.ischecked == true)
          })
        }
      }
    }
  })
})();
